package com.pj.config.security;

import java.util.Base64;

public class Base64Util {
    public static void main(String[] args) {
        // 示例：解码HTTP Basic认证中的凭证
        String encodedCredentials = "Basic Y2xpZW50OnNlY3JldA=="; // 这是"admin:password"经过Base64编码后的字符串

        // 去掉"Basic "前缀
        String pureBase64Encoded = encodedCredentials.substring(6);

        // 解码
        byte[] decodedBytes = Base64.getDecoder().decode(pureBase64Encoded);
        String decodedString = new String(decodedBytes);

        System.out.println("Decoded credentials: " + decodedString); // 输出: admin:password

        String originalBytes = "client:secret";
        System.out.println(Base64.getEncoder().encodeToString(originalBytes.getBytes()));

        String originalBytes2 = "1001:aaaa-bbbb-cccc-dddd-eeee";
        System.out.println(Base64.getEncoder().encodeToString(originalBytes2.getBytes()));
    }
}
